package com.hex.ds.hdrs.log.service;

import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.common.constant.Const;
import com.hex.ds.hdrs.common.utils.BaseUtil;
import com.hex.ds.hdrs.common.utils.HdrsDateUtil;
import com.hex.ds.hdrs.common.utils.MapUtil;
import com.hex.ds.hdrs.log.dao.SmsSendLogDao;
import com.hex.ds.hdrs.log.po.SmsSendLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


/**
 * @author lwz
 * @date 2021-02-23
 * @des
 */
@Service
@Slf4j
public class SmsSendLogService {

    @Autowired
    private SmsSendLogDao smsSendLogDao;

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int add(String phone, String content) {
        SmsSendLog smsSendLog = new SmsSendLog();
        smsSendLog.setPkId(BaseUtil.getPkId());
        smsSendLog.setPhone(phone);
        smsSendLog.setContent(content);
        smsSendLog.setSendStatus(Const.SMS_NOT_SEND);
        smsSendLog.setCrtTs(HdrsDateUtil.getCurrentTime());
        return this.smsSendLogDao.add(smsSendLog);
    }
    /**
     * 分页条件查询
     * @param smsSendLog
     * @param page
     * @return
     */
    public List<SmsSendLog> selectPages (SmsSendLog smsSendLog, Page page){
        log.info("【进入了SmsSendLogService的selectPages】smsSendLog={}" , page);
        Map map = MapUtil.convertObjToMap(smsSendLog);
        return this.smsSendLogDao.selectPages(map, page);
    }
}